package com.example.Mybatis.DynamicDataSource;

import com.example.Enum.DataSourceEnum;


/**
 * 切换数据库操作类
 */
public class CustomContextHolder {

    private static final ThreadLocal <String> contextHolder = new ThreadLocal <String>();

    public static String getCustomerType() {
        //当第一次获取时返回默认的数据链接
        if (contextHolder.get() == null) {
            contextHolder.set(DataSourceEnum.DATA_SOURCE_BUSINESS.getDatasourceBeanName());
        }
        return contextHolder.get();
    }

    public static void setCustomerType(String customerType) {
        contextHolder.set(customerType);
    }

    public static void clearCustomerType() {
        contextHolder.remove();
    }
}
